package com.centit.jksxgl.controller;

import com.centit.jksxgl.po.JddtJksxgl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.centit.jksxgl.service.JddtJksxglManager;
	

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONArray; 
import com.centit.framework.common.JsonResultUtils;
import com.centit.framework.common.ResponseMapData;
import com.centit.framework.core.controller.BaseController;
import com.centit.framework.core.dao.CodeBook;
import com.centit.framework.security.model.CentitUserDetails;
import com.centit.support.algorithm.UuidOpt;
import com.centit.support.database.utils.PageDesc;
import com.centit.util.LayuiResultUtil;

/**
 * JddtJksxgl  Controller.
 * create by scaffold 2020-03-10 
 * @author 脚手架，改成开发者的名字
 * T_JDDT_JKSXGL【监控事项管理表】监控事项管理表   
*/


@Controller
@RequestMapping("/jksxgl/jddtjksxgl")
public class JddtJksxglController  extends BaseController {
	private static final Log log = LogFactory.getLog(JddtJksxglController.class);
	
	@Resource
	private JddtJksxglManager jddtJksxglMag;	
	

    /**
     * 查询所有   T_JDDT_JKSXGL【监控事项管理表】  列表
     *
     * @param field    json中只保存需要的属性名
     * @param request  {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @return {data:[]}
     */
    @RequestMapping(method = RequestMethod.GET)
    public void list(String[] field, PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> searchColumn = convertSearchColumn(request);        
        searchColumn.put("dataValid", "T");
        searchColumn.put(CodeBook.SELF_ORDER_BY, " ins_time desc ");
        JSONArray jsonArrayObjects = jddtJksxglMag.listObjectsAsJson( searchColumn, pageDesc);
        if (null == pageDesc) {
            JsonResultUtils.writeSingleDataJson(jsonArrayObjects, response);
            return;
        }
        ResponseMapData resData = new ResponseMapData();
        resData.addResponseData(OBJLIST, jsonArrayObjects);
        resData.addResponseData(PAGE_DESC, pageDesc);
        LayuiResultUtil.layuiwriteResponseDataAsJson(resData, pageDesc, response);
    }
    
    /**
     * 查询单个  T_JDDT_JKSXGL【监控事项管理表】 
	
	 * @param recId  REC_ID
     *  
     * 
     * @param response    {@link HttpServletResponse}
     * @return {data:{}}
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.GET})
    public void getJddtJksxgl(@PathVariable String recId, HttpServletResponse response, HttpServletRequest request) {
    	String eric = request.getParameter("eric");
    	JddtJksxgl jddtJksxgl = jddtJksxglMag.getObjectById( recId);
    	request.setAttribute("jddtJksxgl", jddtJksxgl);
    	try {
       		if ("view".equals(eric)){
       			request.getRequestDispatcher("/modules/jksxgl/jksxglView.jsp").forward(request, response);
       		}else if("edit".equals(eric)){
       			request.getRequestDispatcher("/modules/jksxgl/jksxglInfo.jsp").forward(request, response);
            }
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
        JsonResultUtils.writeSingleDataJson(jddtJksxgl, response);
    }
    
    /**
     * 新增 T_JDDT_JKSXGL【监控事项管理表】，业务只有新增的时候可用此方法，如有修改可用下面 新增或保存合并的方法
     *
     * @param jddtJksxgl  {@link JddtJksxgl}
     * @return
     */
    @RequestMapping(method = {RequestMethod.POST})
    public void createJddtJksxgl(@Valid JddtJksxgl jddtJksxgl, HttpServletResponse response) {
    	 jddtJksxglMag.saveNewObject(jddtJksxgl);
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }

    /**
     * 删除单个  T_JDDT_JKSXGL【监控事项管理表】 
	
	 * @param recId  REC_ID
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.DELETE})
    public void deleteJddtJksxgl(@PathVariable String recId, HttpServletResponse response, HttpServletRequest request) {
    	CentitUserDetails cud = getLoginUser(request);
    	JddtJksxgl jddtJksxgl = jddtJksxglMag.getObjectById( recId);
    	jddtJksxgl.setDataValid("F");
    	jddtJksxgl.setDelTime(new Date());
    	jddtJksxgl.setDelUsercode(cud.getUserCode());
    	jddtJksxglMag.mergeObject(jddtJksxgl);
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    } 
    
    /**
     * 新增或保存 T_JDDT_JKSXGL【监控事项管理表】 
    
	 * @param recId  REC_ID
	 * @param jddtJksxgl  {@link JddtJksxgl}
     * @param response    {@link HttpServletResponse}
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.PUT})
    public void updateJddtJksxgl(@PathVariable String recId, 
    	@Valid JddtJksxgl jddtJksxgl, HttpServletResponse response, HttpServletRequest request) {
    	CentitUserDetails cud = getLoginUser(request);
    	JddtJksxgl dbJddtJksxgl =  jddtJksxglMag.getObjectById( recId);
        if (null != dbJddtJksxgl) {//如果数据库数据存在，则是更新操作
        	dbJddtJksxgl.copyNotNullProperty(jddtJksxgl);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
        	dbJddtJksxgl.setEditTime(new Date());
        	dbJddtJksxgl.setEditUsercode(cud.getUserCode());
        	jddtJksxglMag.mergeObject(dbJddtJksxgl);
        } else {
        	jddtJksxgl.setRecId(UuidOpt.getUuidAsString32());
        	jddtJksxgl.setDataValid("T");
        	jddtJksxgl.setInsTime(new Date());
        	jddtJksxgl.setInsUsercode(cud.getUserCode());
    		jddtJksxglMag.saveNewObject(jddtJksxgl);//新增,注意主键赋值 UuidUtil.getTimeBasedUuid()，填写自己的业务时间，业务操作人等信息
        }
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }
}
